package com.im.service.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.im.service.common.Result;
import com.im.service.domain.entity.ImGroup;
import com.im.service.domain.vo.ImGroupVO;
import com.im.service.service.ImGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * im-群组 前端控制器
 * </p>
 *
 * @author 刘志强
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/imGroup")
@CrossOrigin
@Slf4j
@Api(tags = "IM群组相关接口")
public class ImGroupController {

    @Autowired
    private ImGroupService groupService;

    @PostMapping("/createGroup")
    @ApiOperation(value = "创建群组")
    public Result<ImGroup> createGroup(@RequestBody ImGroup imGroup) {
        return groupService.createGroup(imGroup);
    }

    @DeleteMapping("/dissolveGroup")
    @ApiOperation(value = "解散群组")
    public Result dissolveGroup(Long id) {
        return groupService.dissolveGroup(id);
    }

    @GetMapping("/groupInfo")
    @ApiOperation(value = "群组详情")
    public Result<ImGroupVO> groupInfo(Long groupId) {
        return groupService.groupInfo(groupId);
    }


    @PutMapping("/updateGroupName")
    @ApiOperation(value = "修改群名称")
    public Result updateGroupName(Long id, String groupName) {
        groupService.update(
                Wrappers.lambdaUpdate(ImGroup.class)
                        .set(ImGroup::getGroupName, groupName)
                        .eq(ImGroup::getId, id)
        );
        return Result.ok();
    }

}
